/*
 * @Author: your name
 * @Date: 2021-11-17 10:14:42
 * @LastEditTime: 2021-11-17 16:57:47
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \app\src\utils\request.js
 */
import axios from "axios"
import {
    Notification
} from 'element-ui'

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'

const service = axios.create({
    baseURL: "/",
    timeout: 1000,
})

// request拦截器
service.interceptors.request.use(
    config => {
        return config
    }, error => {
        console.log('request:error', error)
        Promise.reject(error)
    })

service.interceptors.response.use(
    res => {
        console.log('response:res', res)
        let {
            data,
            data: {
                code,
                text
            }
        } = res;
        if (code == 200)
            return data
        else {
            Notification.error({
                title: text
            })
            return Promise.reject(data)
        }
    }, error => {
        console.log('response:error', error)
        return Promise.reject(error)
    })

export default service